import request from '@/service'

export const uploadDocument = (file, seekerName) => {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('seekerName', seekerName)

  return request.post('/documents/upload', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export const getPendingDocuments = (params = {}) => {
  return request.get('/documents/pending', { params })
}

export const getDocumentsByPage = (params = {}) => {
  return request.get('/documents/list', { params })
}

export const approveDocument = (id, approvedBy) => {
  return request.post(`/documents/${id}/approve`, null, {
    params: { approvedBy }
  })
}

export const rejectDocument = (id, approvedBy, comments) => {
  return request.put(`/documents/${id}/reject`, null, {
    params: { approvedBy, comments }
  })
}

export const downloadTemplate = () => {
  return request.get('/documents/template', {
    responseType: 'blob'
  })
}

export const downloadDocument = (id) => {
  return request.get(`/documents/download/${id}`, {
    responseType: 'blob'
  })
}

export const previewDocument = (id) => {
  return request.get(`/documents/preview/${id}`, {
    responseType: 'blob'
  })
}

export const getDocumentById = (id) => {
  return request.get(`/documents/${id}`)
}
